/**
 * UserProviderImpl.java 2017年06月19日 13:46
 * <p/>
 * Copyright (c) 2010-2016 yinghezhong Inc. All rights reserved.
 *
 * @Description
 * @version 1.0
 */
package com.ql.servicecomb.demo.provider.user;

import com.ql.servicecomb.demo.iserver.user.UserProvider;
import com.ql.servicecomb.demo.model.user.UserModel;
import io.servicecomb.provider.pojo.RpcSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户服务实现
 *
 * @author 齐龙
 * @date 2017年06月19日 13:46
 */
@RpcSchema(schemaId = "userProvider")
public class UserProviderImpl implements UserProvider {
    private final Logger logger = LoggerFactory.getLogger(UserProvider.class);

    @Override
    public UserModel getUser(Integer userId) {
        System.out.println(111);
        UserModel userModel = new UserModel();
        userModel.setUserId(userId);
        userModel.setUsername("username:" + userId);
        userModel.setGender(1);
        userModel.setCreateTime(new Date());
        return userModel;
    }

    @Override
    public List<UserModel> getUserList(Integer page, Integer pageSize) {
        System.out.println(222);
        if (page == null)
            page = 1;
        if (pageSize == null)
            pageSize = 10;
        int start = (page - 1) * pageSize + 1;
        int end = start + pageSize;
        List<UserModel> userModels = new ArrayList<>();
        for (int i = start; i < end; i++) {
            UserModel userModel = new UserModel();
            userModel.setUserId(i);
            userModel.setUsername("username:" + i);
            userModel.setGender(1);
            userModel.setCreateTime(new Date());
            userModels.add(userModel);
        }
        return userModels;
    }

    @Override
    public Integer saveUser(UserModel userModel) {
        System.out.println(333);
        logger.info("[保存UserModel]:{}", userModel.toString());
        return 2;
    }
}
